import { defineComponent, shallowRef, openBlock, createElementBlock, createElementVNode, createBlock, resolveDynamicComponent, toDisplayString } from "vue";
import "../../icons/index.mjs";
import FileExcelIcon from "../../icons/file-excel-icon.vue.mjs";
import FilePptIcon from "../../icons/file-ppt-icon.vue.mjs";
import FilePdfIcon from "../../icons/file-pdf-icon.vue.mjs";
import FileUnkownIcon from "../../icons/file-unkown-icon.vue.mjs";
import FileMarkdownIcon from "../../icons/file-markdown-icon.vue.mjs";
import FileTextIcon from "../../icons/file-text-icon.vue.mjs";
import FileWordIcon from "../../icons/file-word-icon.vue.mjs";
import FileZipIcon from "../../icons/file-zip-icon.vue.mjs";
import FileImageIcon from "../../icons/file-image-icon.vue.mjs";
const _hoisted_1 = { class: "me-file-card-inner" };
const _hoisted_2 = { class: "me-file-card-logo" };
const _hoisted_3 = { class: "me-file-card-content" };
const _hoisted_4 = ["title"];
const _hoisted_5 = { class: "me-file-card-size" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "me-file-card"
  },
  __name: "file-card",
  props: {
    file: {}
  },
  emits: ["click"],
  setup(__props, { emit: __emit }) {
    const emits = __emit;
    const props = __props;
    const fileIconComponents = shallowRef({
      xlsx: FileExcelIcon,
      ppt: FilePptIcon,
      pdf: FilePdfIcon,
      unknown: FileUnkownIcon,
      md: FileMarkdownIcon,
      json: FileTextIcon,
      text: FileTextIcon,
      word: FileWordIcon,
      zip: FileZipIcon,
      png: FileImageIcon,
      jpg: FileImageIcon,
      gif: FileImageIcon,
      jpeg: FileImageIcon
    });
    const getFileSize = (fileSize) => {
      let result = fileSize;
      const units = ["B", "KB", "M", "G", "T"];
      let count = 0;
      const formatUnit = (size) => {
        if (size / 1024 >= 1) {
          if (count < units.length) {
            count++;
            result = Number((size / 1024).toFixed(2));
            formatUnit(result);
          }
        }
        return result + units[count];
      };
      return formatUnit(fileSize);
    };
    const getFileComponent = (fileName) => {
      const arr = fileName.split(".");
      const type = arr[arr.length - 1];
      return fileIconComponents.value[type] || fileIconComponents.value.unknown;
    };
    const onClick = () => {
      emits("click", props.file);
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: "me-file-card",
        onClick
      }, [
        createElementVNode("div", _hoisted_1, [
          createElementVNode("div", _hoisted_2, [
            (openBlock(), createBlock(resolveDynamicComponent(getFileComponent(_ctx.file.name))))
          ]),
          createElementVNode("div", _hoisted_3, [
            createElementVNode("div", {
              class: "me-file-card-name",
              title: _ctx.file.name
            }, toDisplayString(_ctx.file.name), 9, _hoisted_4),
            createElementVNode("div", _hoisted_5, toDisplayString(getFileSize(_ctx.file.size)), 1)
          ])
        ])
      ]);
    };
  }
});
export {
  _sfc_main as default
};
//# sourceMappingURL=file-card.vue2.mjs.map
